\section{Simulation}
\label{section:Simulation}
When executing the code, the interpreter will find the \textit{start} action and run it. In the \textit{start} action the board and the main round are often assigned. After the assignment a graphical user interface (GUI) is built. The board is then scheduled for painting. When the GUI is to be refreshed, we call the paint method of the board, that in turn calls the cells' local paint methods.
\begin{lstlisting}
m_gui.AddPaintable((CLUBsBoard)m_stdenv.GlobalVariables["CurrentBoard"]);
\end{lstlisting}

We start continuously executing the main round. The round node in the decorated AST contains a list of smaller functions\footnote{Corresponding to each statement in the CLUBs source code.} in form of a delegate list. So we just iterate through this list, invoking each delegate.
\begin{lstlisting}
currentInvocation = (Action)roundInvocations[i];
currentInvocation();
\end{lstlisting}
When the loop encounters a \textit{SelectCell} action call, the interpreter waits for a player to click a cell, then executes the code placing the piece and updates the GUI.

This continues until the game ends, in which case the winner is printed and the interpreter stop the execution.

\begin{figure}[h!t]
	\begin{center}
	\includegraphics[width=0.7\textwidth]{./ImplementationReport/Visualflow.pdf}
	\end{center}
	\caption{A flow of the Simulation}
	\label{fig:AflowoftheSimulation}
\end{figure}